package com.wizz.trade.information.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wizz.trade.common.PageVo;
import com.wizz.trade.information.dto.MoneytypeDto;
import com.wizz.trade.information.dto.page.MoneytypePageDto;
import com.wizz.trade.information.entity.Item;
import com.wizz.trade.information.entity.Moneytype;
import com.wizz.trade.information.mapper.MoneytypeMapper;
import com.wizz.trade.information.service.MoneytypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wizz.trade.util.PageUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 货项类型表 服务实现类
 * </p>
 *
 * @author fyftless
 * @since 2023-04-08 12:14:42
 */
@Service
public class MoneytypeServiceImpl extends ServiceImpl<MoneytypeMapper, Moneytype> implements MoneytypeService {

    @Resource
    private MoneytypeMapper moneytypeMapper;

    @Override
    public PageVo<Moneytype> getPage(MoneytypePageDto moneytypePageDto) {
        LambdaQueryWrapper<Moneytype> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(moneytypePageDto.getType()), Moneytype::getType, moneytypePageDto.getType());
        queryWrapper.eq(!Objects.isNull(moneytypePageDto.getMoney()),Moneytype::getMoney,moneytypePageDto.getMoney());
        IPage<Moneytype> page = moneytypeMapper.selectPage(PageUtil.initPage(moneytypePageDto), queryWrapper);
        return new PageVo<>(page);
    }

    @Override
    public List<Integer> getMoneyOption() {
        return moneytypeMapper.getMoneyOption();
    }

    @Override
    public List<Map<Integer, String>> getTypeOption(Integer money) {
        return moneytypeMapper.getTypeOption(money);
    }
}
